package com.example.jedis_pool.test;

import com.example.jedis_pool.jedis_config.Config;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Tuple;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class testZset {

    public static void main(String[] args) {

        testZset.setKeyValue();
        testZset.getKeyValue();
        //关闭连接
        jedis.close();
    }
    //获取连接
    private static Jedis jedis= Config.JedisPool().getResource();


    public static void setKeyValue(){

        jedis.select(4);
        jedis.flushDB();

        jedis.zadd("zset",1,"zset-value-0");
        jedis.zincrby("zset",1,"zset-value-0");

        Map map = new HashMap();
        map.put("zset-value-1",2.00);
        map.put("zset-value-2",3.00);
        map.put("zset-value-3",4.00);
        map.put("zset-value-4",5.00);
        map.put("zset-value-5",6.00);
        jedis.zadd("zset",map);
        long l = jedis.zcount("zset",3,5);//[区间为两端都闭]
        System.out.println("zcount的返回值"+l);

        jedis.zrevrangeByScore("zset",0,-1);
        Set<Tuple> zs = jedis.zrangeByScoreWithScores("zset", 2, 5);
        System.out.println("zs的返回值"+zs);//有序输出
    }

    public static void getKeyValue(){

       Long l= jedis.zrank("zset","zset-value-3");//排名从0开始
       System.out.println(l);


    }


}
